package com.sailfish.springbootdemo.controller.db2;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db2.PcbApproveConfig;
import com.sailfish.springbootdemo.service.db2.PcbApproveConfigService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/pcbApproveConfig")
public class PcbApproveConfigController {

    @Autowired
    PcbApproveConfigService pcbApproveConfigService;

    @PostMapping("/getApproveConfigList")
    public Result getList(String searchK, String searchV) {
        PcbApproveConfig param = new PcbApproveConfig();
        if (!StringUtils.isBlank(searchK)) {
            if (searchK.equals("flowType")) {
                param.setFlowTypeName(searchV);
            }
            if (searchK.equals("parentFactory")) {
                param.setParentFactoryName(searchV);
            }
            if (searchK.equals("sonFactory")) {
                param.setSonFactoryName(searchV);
            }
        }
        final List<PcbApproveConfig> list = pcbApproveConfigService.getList(param);
        return ResultUtil.success(list);
    }

    @PostMapping("/getApproveConfig")
    public Result getApproveConfig(Integer flowType, Integer sonFactoryId) {
        PcbApproveConfig param = new PcbApproveConfig();
        param.setFlowType(flowType);
        param.setSonFactoryId(sonFactoryId);
        List<PcbApproveConfig> list = pcbApproveConfigService.getList(param);
        return ResultUtil.success(list);
    }

    @PostMapping("/insertOrUpdateApproveConfig")
    public Result insertOrUpdate(@RequestBody String data) {
        return pcbApproveConfigService.insertOrUpdate(data);
    }

    @PostMapping("/deleteApproveConfig")
    public Result delete(Integer id) {
        return pcbApproveConfigService.delete(id);
    }


}
